package com.aiden.cashbook

import android.content.Intent
import android.os.Bundle
import android.support.v4.view.GravityCompat
import android.support.v4.widget.DrawerLayout
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import android.view.View
import android.widget.LinearLayout
import com.aiden.cashbook.base.BaseActivity
import com.aiden.cashbook.bill.dagger.DaggerBillListFragmentComponent
import com.aiden.cashbook.bill.BillListFragment
import com.aiden.cashbook.charge.ChargeActivity
import kotlinx.android.synthetic.main.activity_main.*
import javax.inject.Inject

class MainActivity : BaseActivity() {


    @Inject
    lateinit var mBillFragment: BillListFragment

    override fun onCreate() {
        DaggerBillListFragmentComponent.builder().build().inject(this)
        setContentView(R.layout.activity_main)
        hideToolbar()
    }

    override fun initData() {
        supportFragmentManager.beginTransaction().add(R.id.fl_content, mBillFragment).show(mBillFragment).commit()
        drawer_main.addDrawerListener(object : DrawerLayout.DrawerListener {
            override fun onDrawerSlide(drawerView: View, slideOffset: Float) {

            }

            override fun onDrawerClosed(drawerView: View) {
            }

            override fun onDrawerOpened(drawerView: View) {
            }

            override fun onDrawerStateChanged(newState: Int) {

            }

        })

        val headerView = nav_main.getHeaderView(0)
        headerView.findViewById<LinearLayout>(R.id.ll_login).visibility = View.VISIBLE
        nav_main.setNavigationItemSelectedListener { item: MenuItem ->
            when(item.itemId) {
                R.id.account -> drawer_main.closeDrawer(GravityCompat.START) //TODO 记账本
                R.id.setting -> startActivity(Intent(this, ChargeActivity::class.java)) //TODO 设置
            }
            true
        }
    }

    fun onUserClicked(view: View) {
        //TODO 跳转用户个人中心
    }

    fun onLoginClicked(view: View) {
        //TODO 跳转登录
    }
}
